package h0909;

import java.util.HashMap;

public class LongestPalindromeString {
    public static void main(String[] args) {

    }

    public int longestPalindrome(String s) {
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            map.put(c, map.getOrDefault(c, 0) + 1);
        }
        int maxLen=0;
        boolean hasodd=false;
        for (Integer value : map.values()) {
            if (value%2==0){
                maxLen+=value;
            }else {
                maxLen+=value-1;
                hasodd=true;
            }
        }
        if (hasodd){
            maxLen+=1;
        }
        return maxLen;
    }
}
